/**
 * Terrain Interpolation Vertex Shader
 *
 * Adds detail to terrain meshes
 * Requires Shader Model 3.0
 **/

//uniform mat4 gl_ModelViewProjectionMatrix;

uniform sampler2DRect	gHeightMap;
uniform vec3		gScale;

//attribute vec4 gl_Vertex;
//attribute vec4 gl_Position;

varying vec2		vTexCoords;

void main() {
	vec4 v = gl_ModelViewProjectionMatrix * vec4(gl_Vertex.x * gScale.x, gl_Vertex.y * gScale.y, gl_Vertex.z * gScale.z, gl_Vertex.w);

	vec3 vH = texture2DRect(gHeightMap, vec2(gl_Vertex.x / 256, gl_Vertex.z / 256)).rgb;
	float h = vH.r + (vH.g * 256) + (vH.b * 256 * 256);

	vTexCoords = vec2(gl_MultiTexCoord0);
	gl_Position = vec4(v.x, v.y + (h * gScale.y), v.z, v.w);
}
